package cn.lupin.config;

import cn.lupin.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/**")
				.addResourceLocations("classpath:/META-INF/resources/")
				.addResourceLocations("file:/root/app/laugh-videos-backend/files/")
				.addResourceLocations("file:/root/app/laugh-videos-backend/");
	}

	@Bean
	public LoginInterceptor loginInterceptor(){
		return new LoginInterceptor();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(loginInterceptor()).addPathPatterns("/user/**")
													.excludePathPatterns("/user/queryPublisher")
													.addPathPatterns("/bgm/**")
													.addPathPatterns("/video/upload",
																	 "/video/uploadCover",
																	 "/video/userLike",
																	 "/video/userUnLike");
		super.addInterceptors(registry);
	}
}
